//index.js
var date = new Date();
var myDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
var app = getApp()
Page({
  data: {
    id:'',
    status:1,
    tabs: [{ name: '团', url: '../edit/edit?status=1' }, { name: '券', url: '../edit/edit?status=2' }, { name: '拼', url: '../edit/edit?status=3' }, { name: '免', url: '../edit/edit?status=4' }],
    has: [{ name: '', num: '', total: '' }],
    imgs:[],
    date: '起始时间',
    date3: '截止时间',
    date2: '',
    time: '9:00',
    time2: '20:00',
    newindex: 0,
    newindex2: 0,


  },
  datepick: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  datepick2: function (e) {
    this.setData({
      date3: e.detail.value
    })
  },
  timepick: function (e) {
    this.setData({
      time: e.detail.value
    })
  },
  timepick2: function (e) {
    this.setData({
      time2: e.detail.value
    })
  },
  chooseImg: function () {
    var _this = this;
    wx.chooseImage({
      count: 5, // 默认9
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'],
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        _this.setData({
          imgs: res.tempFilePaths
        })
      }
    })
  },
  delete: function (e) {
    let index = e.currentTarget.dataset.index;
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
          var datas = that.data.imgs;
          datas.splice(index, 1);
          that.setData({ imgs: datas })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }, 
  addon:function(){
  var data=this.data.has;
  var that=this;
  wx.showModal({
    title: '提示',
    content: '确定要新增一个吗？',
    success: function (sm) {
      if (sm.confirm) {
        data.push({ name: '', num: '', total: '' });
        that.setData({
          has: data
        })
      } else if (sm.cancel) {
        console.log('用户点击取消')
      }
    }
  })

  },
  destory:function(e){
    let index = e.currentTarget.dataset.index;
    var that=this
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
          var datas = that.data.has;
          datas.splice(index, 1);
          that.setData({ has: datas })
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  add1:function(e){
    let index = e.currentTarget.dataset.index;
    this.setData({
      ['has[' + index + '].name']: e.detail.value
    });
  },
  add2: function (e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      ['has[' + index + '].num']: e.detail.value
    });
  },
  add3: function (e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      ['has[' + index + '].total']: e.detail.value
    });
  },
  onLoad: function (e) {
    this.setData({
      date2: myDate,
      id:e.id,
      status:e.status,
    })


  }
})  
